Part Number Hot Search : 
SA532 TM32F M37207 MA568 TD6207 SRF2070 M18BCK LCR400
Product Description
Full Text Search
 

To Download AN1149 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  AN1149/0699 1/17 application note handling suspend mode on a usb mouse by microcontroller division application team introduction all usb devices must support suspend mode. suspend mode enables the devices to enter low-power mode if no bus activity is detected for more than 3.0 ms. like usb keyboards and pointing devices, usb mice must be able to exit suspend mode if a button has been pressed or if a movement has been detected. this feature is called remote wake-up mode. a remote wake-up involves a resume sequence on the usb lines and re- covery of communication between the mouse and the host. the following application note describes the implementation of suspend and remote wake-up modes on a usb mouse using the st7263 microcontroller. the first chapter focuses on the recommendations before entering suspend mode. then a description of the rc external cir- cuit for handling remote wake-up mode is detailed. it contains power management recom- mendations and rc value proposals. the third chapter describes resume mode. then chapter 4 and chapter 5 describe software implementation and program flow. it is assumed that the reader is familiar with the st7263 microcontroller and usb. 1
2/17 table of contents 17 1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 entering suspend mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.1 specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.2 st7263 implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.3 recommendations before entering suspend mode . . . . . . . . . . . . 3 2 exiting suspend mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.1 specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.2 st7263 implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.3 external rc circuit implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.4 photo transistors timing requirements . . . . . . . . . . . . . . . . . . . . . . 7 2.5 rc time constant calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3 resume mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4 software implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 5 program flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 reference documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3/17 handling suspend mode on a usb mouse 1 entering suspend mode 1.1 specification the usb mouse must be able to enter suspend mode from any powered state. it goes into suspend mode when it detects a constant idle state on the usb data lines for more than 3.0 ms. (no start of frames are issued by the host for more than 3.0 ms). any bus activity keeps the mouse out of the suspend state. when the mouse is in the suspend state, it must draw less than 500 m a from the bus. 1.2 st7263 implementation all the st7263 microcontroller usb events are managed by interrupts. as soon as a constant idle state occurs for more than 3.0 ms, the suspend bit of the interrupt status register (istr) is set by hardware. then, the firmware determines the interrupt origin by reading the istr register, sets a bit in a software register (bmusbintflag), and clears the interrupt flag. the usb polling routine reads the software register (bmusbintflag) to determine the usb in- terrupt source and jumps to the corresponding interrupt routine. to get the 500 m a specification, the st7263 microcontroller must be placed in halt low- power mode . halt mode is entered by executing the halt instruction in the suspend in- terrupt routine. the internal oscillator is then turned off, causing all internal processing to be stopped, including the operation of the on-chip peripherals. 1.3 recommendations before entering suspend mode special care must be taken of the st7263 port configuration before entering suspend mode. the ports a and c contain integrated pull-up resistors. if these ports are configured as inputs, they draw about 50 m a on each pin. (see st7263 data sheet electrical characteristics). this means that the 8 port a pins and the 3 port c pins could draw 550 m a together. consequently it would be impossible to get the 500 m a current consumption specification. then port a and port c must then be therefor configured as outputs before entering suspend mode. correct voltage values must be applied to the output pins to make the current con- sumption as low as possible. port b does not contain any integrated pull-up resistor, but external pull-up resistors are im- plemented in hardware at the photo transistor outputs. thus it is strongly recommended to configure these as outputs and to apply a 5v value on each pin before entering suspend mode. 2
4/17 handling suspend mode on a usb mouse 2 exiting suspend mode 2.1 specification a usb mouse can be woken-up from suspend state by switching the bus state to the resume state, by normal bus activity, or by signalling a reset. a mouse device can be woken-up by ac- tions associated with internal functions and then cause signalling on its upstream connections to wake or alert the rest of the system. this feature is called remote wake-up. 2.2 st7263 implementation all the st7263 microcontroller usb events are managed by interrupts. the st7263 microcontroller exits suspend mode when one of the following events occurs: a) usb reset on the usb data lines for more than 10 ms min and 20 ms max. the microcontroller exits halt mode and jumps to the usb reset interrupt routine. b) resume signal on the usb data lines from upstream devices for at least 20 ms. the microcontroller exits halt mode and jumps to the usb_end_suspend interrupt routine. c) external interrupt on a pin of the microcontroller (it can either be a rising or falling edge or a level change). the oscillator is then turned on, the microcontroller exits halt mode and jumps to the corresponding interrupt routine. this external interrupt is very important for managing remote wake-up mode. as described in the previous section, when the microcontroller enters halt mode, it must draw less than 500 m a average and it must be able to check if a mouse button has been pressed or if the mouse as been moved. this implies that external interrupt must periodically wake-up the microcon- troller to make it check its port states. the following section proposes a cost effective solution for generating this periodic external in- terrupt. 2.3 external rc circuit implementation during suspend mode, as the internal oscillator has been turned off, we must use an external event to generate an interrupt on a dedicated pin of the microcontroller. moreover this interrupt signal must occur periodically. the most common and cost-effective solution consists of using an external rc circuit.
5/17 handling suspend mode on a usb mouse figure 1. rc external circuitry an external capacitor loads through an external resistor. this capacitor is connected to the pb5 external interrupt pin of the microcontroller. as soon as the capacitor load has reached the low-to-high trigger level, the external interrupt vector is set. then, the entire microcon- troller is woken-up: the internal oscillator is turned on, causing all internal processing to resume, including the operations of the on-chip peripherals. if the mouse has moved or if the buttons have been pressed, the application performs a re- mote wake-up sequence, otherwise the application discharges the capacitor and re-enters suspend mode. figure 2. shows the rc circuit behaviour when the mouse is not moved. figure 2. rc circuit behaviour in suspend mode vdd vss pb5 st7263 r c pax pbx photo transistors and buttons pb5 is successively configured as an input with interrupt during suspend phase and as an output during a wake-up phase oscillator activity external capacitor charge and discharge zoom in figure 3
6/17 handling suspend mode on a usb mouse during the charge of the capacitor, the microcontroller is in low-power mode, it draws only about 250 m a. as soon as the charge of the capacitor reaches the low-to-high interrupt trigger value (about 3.35 v), the microcontroller wakes-up. the oscillator is then turned on and a sta- bilization time is required before releasing cpu clock cycles. this stabilization time is 4096 cpu clock cycles. during this activity phase, the microcontroller draws about 20 ma. this os- cillator wake-up phase is shown in figure 3. figure 3. oscillator wake-up sequence 4096 cpu clocks external capacitor charge oscillator activity and discharge for these 800 m s, the micro draws 20 ma
7/17 handling suspend mode on a usb mouse 2.4 photo transistors timing requirements to check if the mouse has moved, it is necessary to compare the current state of the photo transistor outputs with the previous ones (recorded before entering suspend mode). as soon as the microcontroller executes its program code, the infra red leds of the mouse are turned on. however, to establish the previous photo transistor values (especially in case of high level values) a certain amount of time is required. this period is less than 200 m s with the components used . this is due to current establishment in the infra-red diode. figure 4. photo transistor behaviour mouse infra red power supply active on low level photo transistor output high level establishment external capacitor charge and discharge oscillator activity 220 m s to the program code handling before re-entering corresponding halt mode at this point, the current value is read and compared to the previous one. if the mouse has not been moved, the mouse re-enters suspend mode otherwise we perform a remote wake-up sequence
8/17 handling suspend mode on a usb mouse 2.5 rc time constant calculation as shown on the previous oscillogram, the microcontroller is active for 800 m s and it draws 20 ma. it is in low-power mode during the rest of the period and draws about 250 m a. the following equation enables you to calculate the correct value of the rc time period to be within the suspend mode 500 m a average max current specification: example: if you choose 450 m a to stay well within the specification and with the following parameters: imax = 20 ma - wakeuptime = 800 m s - imin = 250 m a you obtain the following equation: a period value of 80 ms is obtained. the rc value can then be calculated to get this period. you need to pay attention to 2 parameters: C the high level voltage imposed by the high trigger level (about 3.4v with a +/- 10% variation). C the input impedance of the pin which modifies the equivalent resistance of the rc circuit. the following table presents some rc values and the corresponding time periods and con- sumption measured on a st7263 microcontroller. depending on the application supporting suspend mode, you will have to find a compromise between the suspend interval time and the suspend average current. table 1. rc value proposal note 1: suspend mode consumption has been measured with ports a and c configured as outputs (this has been done to avoid additional current consumption in their pull-up resistors) rc values suspend interval time suspend average current c= 330 nf - r= 1 m w t= 306 ms i= 400 m a c= 330 nf - r= 670 k w t= 200 ms i= 405 m a c= 330 nf - r= 330 k w t= 97 ms i= 440 m a c= 100 nf - r= 670 k w t= 80 ms i= 450 m a c= 100 nf - r= 330 k w t= 37 ms i= 540 m a (out of spec.) specvalue imax wakeuptime ) imin period wakeuptime C () () + () period ------------------------------------------------------------------------------------------------------------------------------- --------------------------- = 450 m s 20 ma 800 m s ) 250 (m aperiod 800 m s C () + () period -------------------------------------------------------------------------------------------------------------- =
9/17 handling suspend mode on a usb mouse note 2: a usb mouse is a human interface device. this means that it is manipulated by an operator at quite a low frequency. for mouse pointing devices, the best compromise is ob- tained by chosing an rc value which allows you to enter remote wake-up mode and fre- quently check the device sensor states (10 times per second is enough).
10/17 handling suspend mode on a usb mouse 3 resume mode as soon as a different value has been read from the buttons or photo transistor outputs, the microcontroller performs a remote wake-up sequence to resume the communication flow be- tween the device and the host. an example of such a sequence is shown in figure 5. figure 5. resume state behaviour note that the dm and dp lines are maintained in resume state for 21.6 ms while the usb specification release 1.1 requires the device to assert resume signalling for a period between 10 ms and 15 ms. in fact the device asserts suspend state for only 12 ms and then the host maintain this state for 21.6 ms. this 20 ms minimum resume signalling time insures that all devices in the network that are enabled to see the resume are woken-up. commute from constant idle state to resume state for a previous photo transistor value photo transistor output oscillator activity (checked every 80 ms) dm line dp line period for 10 to 15 ms the mouse is moved by user
11/17 handling suspend mode on a usb mouse 4 software implementation in the following section, all the programs have been developed using the hiware c compiler toolchain. st provides a complete architecture as well as firmware drivers to help you de- velop your application quickly and easily. a list of reference documents is provided at the end of the application note. depending on the st7263 microcontroller, all usb events are managed by interrupt. when an usb event occurs, a flag of the interrupt state register (istr) is set by hardware. then, the firmware determines the interrupt origin by reading the istr register, sets the corresponding bit in a software register (bmusbintflag), and clears the interrupt flag. the usb polling routine reads the software register (bmusbintflag) to determine the usb interrupt source and jumps to the corresponding interrupt routine. each interrupt routine sets the global variable bmusbstate to the corresponding usb state: sof, ennumerated, suspended or remote wake-up. in the check_usbstate.c file you only have to adapt your code to the example given below to handle resume and remote wake-up modes. dont forget to put all the i/os in low-power mode in order to draw less than 500a. figure 6. shows the flow-chart of the main application loop.
12/17 handling suspend mode on a usb mouse figure 6. usb suspend / remote wake-up handling the remote wake-up command is sent from device to host. this happens when the microcon- troller has been suspended and an external interrupt (pb5) restarts the oscillator. to send a remote wake up signal, the bmusbstate variable is set in the check_usbstate.c file if the mouse has been moved. otherwise, we re-enter suspend mode. if (bmusbstate & suspend) if (bmusbstate & remote_wakeup) n n application (check_mouse_state) y before_bmusbstate function after_bmusbstate function halt (low-power mode instruction) main application loop if the mouse moved external interrupt detection n bm_usbsate = remote_wakeup done force resume signal on usb bus y done y
13/17 handling suspend mode on a usb mouse 5 program flow the following code gives an example of a usb mouse application for handling suspend and remote wake-up modes. /*-------------------------------------------------------------------------- routine name : before_enter_suspend input/output : description : this function details what we have to do before entering suspend mode /*-------------------------------------------------------------------------- void before_enter_suspend(void) { unsigned int k; // variable used in the capacitor discharge loop paddr = 0xff; // the 2 ports are configured in output for minimum current consumption pcddr = 0xff; setbit(pbddr,5); // pb5 in output mode (external rc circuit) clrbit(pbdr,5); // clr pb5 : discharge the external capacitor for (k=17; k>0;k --) // 50us loop: this time interval is mandatory to asm nop; // completly discharge the external capacitor previous_suspend_state = (pbdr & 0xd8); // read the phototransistor value be- fore entering suspend current_suspend_state = previous_suspend_state; setbit(pcdr,0); // switch off the mouse led clrbit(pbddr,5); // pb5 configured in input mode (we let the capacitor charge) wake_up_flag = 0; itrfre |= 0x20; // enable it6 (pb5) } /*-------------------------------------------------------------------------- routine name : after_end_suspend input/output : description : this function details what we have to do after exiting from suspend mode /*-------------------------------------------------------------------------- void after_end_suspend(void) { unsigned int j; // variable used in the 200 us loop if (wake_up_flag == 1) { clrbit(pcdr,0); // switch on the mouse led setbit(pbddr,5); // pb5 in output mode (external rc circuit) clrbit(pbdr,5); // clr pb5 : discharge the external capacitor itrfre |= 0x20; // re enable it5 for (j=68; j>0; j--) // 200us loop: this time interval is mandatory to let
14/17 handling suspend mode on a usb mouse asm nop; } // each phototransistor reach his previous value } /*-------------------------------------------------------------------------- routine name : check_bmusbstate input/output : description : this subroutine polls the usb global variable bmusbstate /*-------------------------------------------------------------------------- void check_bmusbstate(void) { if(bmusbstate & suspend) { before_enter_suspend(); asm { loop: halt; // enters suspend mode } /***** return from interrupt in suspend mode *******/ after_end_suspend(); current_suspend_state = (pbdr & 0xd8); // filter on the 4 x-y axis optocou- pler sensors if (current_suspend_state == previous_suspend_state) { current_suspend_state = previous_suspend_state; setbit(pcdr,0); // switch off the mouse led clrbit(pbddr,5); // pb5 configured in input (we let the capacitor charge) itrfre |= 0x20; // re enable it6 wake_up_flag = 0; asm jp loop; } else { itrfre = 0x00; // disable it6 (pb5) bmusbstate &= ~suspend; // reset "go suspend" bmusbstate |= remote_wakeup; // set "remote wake-up" clrbit(pbddr,5); // pb5 configured in input } } if(bmusbstate & remote_wakeup) remotewakeup();
15/17 handling suspend mode on a usb mouse if(bmusbstate & sof) { bmusbstate &= ~sof; // reset the sof bit mouse_counter++; // this variable is used to refresh the cursor position } if(bmusbstate & sof) nop; } /*-------------------------------------------------------------------------- routine name : int_it1it8 input/output : none description : rising edge interrupt comments : /*-------------------------------------------------------------------------- #pragma trap_proc save_regs void int_it1it8(void) { if(bmusbstate & suspend) // we are in suspend mode { if((pbdr & 0x20) == 0x20) wake_up_flag =1; } }
16/17 handling suspend mode on a usb mouse reference documents C st7263 data sheet C an 1017 using the st7 universal serial bus microcontroller C an 1069 developing an st7 usb apllicaton C an 989 starting with st7 hiware c. C an 1064 writing optimized hiware c language for st7 a general training for st7 (hardware and development tools) is available on the st7 cd- rom. the usb descriptor tool dt2.4 is available on the usb website at url http//www.usb.org
17/17 handling suspend mode on a usb mouse "the present note which is for guidance only aims at providing customers with information regarding their products in order for them to save time. as a result, stmicroelectronics shall not be held liable for any direct, indirect or consequential damages with respect to any claims arising from the content of such a note and/or the use made by customers of the information contained herein in connexion with their products." information furnished is believed to be accurate and reliable. however, stmicroelectronics assumes no responsibility for the co nsequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. no license is granted by implication or otherwise under any patent or patent rights of stmicroelectronics. specifications mentioned in this publicati on are subject to change without notice. this publication supersedes and replaces all information previously supplied. stmicroelectronics prod ucts are not authorized for use as critical components in life support devices or systems without the express written approval of stmicroele ctronics. the st logo is a registered trademark of stmicroelectronics ? 1999 stmicroelectronics - all rights reserved. purchase of i 2 c components by stmicroelectronics conveys a license under the philips i 2 c patent. rights to use these components in an i 2 c system is granted provided that the system conforms to the i 2 c standard specification as defined by philips. stmicroelectronics group of companies australia - brazil - china - finland - france - germany - hong kong - india - italy - japan - malaysia - malta - morocco - sin gapore - spain sweden - switzerland - united kingdom - u.s.a. http://www.st.com


▲Up To Search▲   

 
Price & Availability of AN1149

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X